var intervalId;

function autoChangeProduct() {
	var productList = jQuery('.hotProduct li');
	if (productList.length > 1) {
		var currentProduct = productList.filter(function(index) {
			return jQuery(productList[index]).css('opacity') == 1;
		});
		if (currentProduct.length <= 0) {
			currentProduct = jQuery(productList[0]);
		}

		var nextProduct = currentProduct.next();
		if (nextProduct.length <= 0) {
			nextProduct = jQuery(productList[0]);
		}

		// Fade out all
		productList.fadeTo(300, 0.4);

		// Fade in
		nextProduct.fadeTo(500, 1, function() { if (jQuery.browser.msie) { nextProduct.css('filter', ''); } });

		// Show
		setTimeout(function() { showProduct(nextProduct); }, 400);

	}
}

function manualChangeProduct(selectedProduct) {
	var productList = jQuery('.hotProduct li');

	// Clear interval
	clearInterval(intervalId);

	// Fade out all
	productList.fadeTo(300, 0.4);

	// Fade in
	selectedProduct.fadeTo(500, 1, function() { if (jQuery.browser.msie) { selectedProduct.css('filter', ''); } });

	// Show
	showProduct(selectedProduct);

	// Auto fade
	intervalId = setInterval('autoChangeProduct();', 5000);
}

function showProduct(product) {
	var productView = jQuery('.product-view');
	productView.fadeTo(200, 0.6);
	jQuery('#proImage').attr('src', product.find('img').attr('src'));
	jQuery('#proTitle').html(product.find('.title').html());
	jQuery('#proInfo').html(product.find('.info').html());
	jQuery('#proLink').attr('href', product.find('.detail').attr('href'));
	productView.fadeTo(500, 1, function() { if (jQuery.browser.msie) { productView.css('filter', ''); } });
}